package com.zhuojy.equity.mall.admin.web.controller;

import com.zhuojy.equity.mall.admin.common.entity.bo.HolidayBO;
import com.zhuojy.equity.mall.admin.common.entity.po.THolidayPo;
import com.zhuojy.equity.mall.admin.common.entity.TUser;
import com.zhuojy.equity.mall.admin.common.entity.vo.HolidayVO;
import com.zhuojy.equity.mall.admin.common.support.JsonResult;
import com.zhuojy.equity.mall.admin.service.THolidayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "假期类型管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("holiday")
@CrossOrigin
public class THolidayController {
    @Autowired
    private THolidayService holidayService;

    /**
     * 测试查询
     *
     * @param tHoliday
     * @return
     */
    @ApiOperation(value = "测试假期类型查询", httpMethod = "POST", notes = "测试假期类型查询")
    @RequestMapping("findtholiday")
    public List<THolidayPo> findtholiday(@RequestBody THolidayPo tHoliday) {
        return holidayService.findtholiday(tHoliday);
    }

    /**
     * 假期类型条查+分页
     */
    @ApiOperation(value = "假期类型条查分页", httpMethod = "POST", notes = "假期类型条查分页")
    @RequestMapping("findholidayPagination")
    public JsonResult findholidayPagination(@RequestBody THolidayPo tHoliday, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return holidayService.findholidayPagination(tHoliday, pageNum, pageSize);
    }

    /**
     * 假期类型新增
     */
    @ApiOperation(value = "假期类型新增",httpMethod = "POST",notes = "假期类型新增")
    @RequestMapping("addHoliday")
    public JsonResult addHoliday(@RequestBody HolidayBO holidayBO) {
        try {
            holidayService.addHoliday(holidayBO);
            return JsonResult.success(200,"新增成功");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.success(444,"新增失败");
        }
    }

    /**
     * 假期类型删除(单删)
     */
    @ApiOperation(value = "假期类型删除", httpMethod = "POST", notes = "假期类型删除")
    @RequestMapping("deleteHoliday")
    public JsonResult deleteHoliday(@RequestParam Integer id) {
        try {
            holidayService.deleteHoliday(id);
            return JsonResult.success(200, "删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.success(444, "删除失败");
        }
    }
    /**
     * 假期类型表回显
     */
    @ApiOperation(value = "假期类型表回显", httpMethod = "POST", notes = "假期类型表回显")
    @RequestMapping("findholidayId")
    public HolidayVO findholidayId(Integer id){
        return holidayService.findholidayId(id);
    }
    /**
     * 假期类型表修改
     */
    @ApiOperation(value = "假期类型表修改", httpMethod = "POST", notes = "假期类型表修改")
    @RequestMapping("updateHoliday")
    public JsonResult updateHoliday(@RequestBody HolidayBO holidayBO){
        try {
            holidayService.updateHoliday(holidayBO);
            return JsonResult.success(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.success(444,"修改失败");
        }
    }
    /**
     * 假期表新增负责人动态下拉列表
     */
    @ApiOperation(value = "假期表新增负责人动态下拉列表", httpMethod = "POST", notes = "假期表新增负责人动态下拉列表")
    @RequestMapping("findOptions")
    public List<TUser> findOptions(){
        return holidayService.findOptions();
    }
}
